#include <iostream>

#include <GA\Task\UniTranspTask.hpp>
#include <GA\BinaryString\BoolArray.hpp>
#include <GA\GA.hpp>
#include <GA\Task\Factory\UniTranspTaskFactory.hpp>


#define POPULATION_SIZE 500
#define GENERATIONS 10000


int main( ) {

  // Making aliases
  using std::vector;
  using std::list;
  using std::shared_ptr;

  using std::cout;
  using std::endl;

  using unitraf::UniTranspTask;
  using unitraf::UniTranspTaskFactory;
  using unitraf::GA;
  using unitraf::BinaryString;
  
  // Genetic Algorithm applying

	UniTranspTaskFactory factory;

	shared_ptr<UniTranspTask> task(factory.createUniTranspTask( ));

  GA ga( POPULATION_SIZE, &factory, task.get() );

	for ( size_t i = 0; i < GENERATIONS; ++i ) {
		ga.nextGen( ); 
		cout << i << ") " << task->fitness( ga.best( ) ) << endl; 

		/*vector<size_t> solution;

		task->decode( ga.best( ), solution );

		for ( size_t i = 0; i < solution.size( ); ++i )
		{
			cout << solution[i] << endl;
		}*/

	}

	cout << "----------------------------results:------------------------\n";

	vector<UniTranspTask::Route> solution;

	task->decode( ga.best( ), solution );

	for ( size_t i = 0; i < solution.size( ); ++i )
	{
		cout << solution[i]._n << '\t' << solution[i]._size << endl;
	}

	
	return 0;

}